package asynwrap

import(
	"github.com/sniperHW/kendynet/event"
	"github.com/sniperHW/kendynet/asyn"
	"sync"
	"reflect"
)

var queue *event.EventQueue
var once sync.Once

type wrapFunc func(callback func([]interface{}),args ...interface{})

func Init(queue_ *event.EventQueue) {
	if nil == queue_ {
		panic("queue_ == nil")
	}

	once.Do(func() {
		queue = queue_
	})
}

func Wrap(oriFunc interface{}) wrapFunc {
	oriF := reflect.ValueOf(oriFunc)
	if oriF.Kind() != reflect.Func {
		panic("oriFunc is not a function")
	}

	return wrapFunc(asyn.AsynWrap(queue,oriFunc)) 

} 